package com.mdb.open.trade.resource;
/*
 * Copyright (C), 2017-2019 澳发科技(MDB)
 * FileName: MerchantResource.java
 * Author:   符楚
 * Date:     2019-10-10 15:06
 * History:
 * <author>          <time>          <version>          <desc>
 * 符楚               2019-10-10          V1.00             新建
 * -----------------------------------------------------------
 * 作者姓名           修改时间           版本号            描述
 */

import com.mdb.bc.api.data.ListResultEx;
import com.mdb.bc.api.data.PageVo;
import com.mdb.bc.api.data.ResultEx;
import com.mdb.bc.logger.LogAnnotation;
import com.mdb.bc.web.RepeatSubmitTypeEnum;
import com.mdb.bc.web.annotation.DenyRepeatSubmit;
import com.mdb.bc.web.support.SuperResources;
import com.mdb.open.trade.domain.dto.customer.MerchantInfoDto;
import com.mdb.open.trade.domain.dto.customer.PMerchantInfoDto;
import com.mdb.open.trade.domain.dto.customer.QMerchantInfoDto;
import com.mdb.open.trade.domain.vo.customer.MerchantInfoVo;
import com.mdb.open.trade.domain.vo.customer.SaveMerchantInfoVo;
import com.mdb.open.trade.facade.MerchantInfoFacade;
import com.mdb.user.LoginUserInfoHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 商户信息资源<br>
 * <br>
 *
 * @author 符楚
 * @Date 2019-10-10 15:06
 */
@RestController
@RequestMapping("merchant")
@Api(tags = {"子账号管理"})
public class MerchantResource extends SuperResources {

    @Autowired
    MerchantInfoFacade merchantInfoFacade;

    @Autowired
    LoginUserInfoHelper loginUserInfoHelper;


    @DenyRepeatSubmit(type = RepeatSubmitTypeEnum.EXCLUSIVE_SUBMIT)
    @LogAnnotation
    @ApiOperation("子账号开通")
    @PostMapping
    public ResultEx<SaveMerchantInfoVo> save(@RequestBody MerchantInfoDto saveDto) {
        return merchantInfoFacade.save(saveDto, loginUserInfoHelper.getLoginInfo().getUserName(), loginUserInfoHelper.getUserId(true), loginUserInfoHelper.getCustomerCode(true));
    }


    @LogAnnotation
    @ApiOperation("子账号列表")
    @GetMapping
    public ListResultEx<MerchantInfoVo> findByCondition(@ModelAttribute PageVo pageVo, @ModelAttribute QMerchantInfoDto qMerchantInfoDto) {
        return merchantInfoFacade.findByCondition(pageVo, qMerchantInfoDto, this.loginUserInfoHelper.getCustomerCode(true));
    }


    @LogAnnotation
    @ApiOperation("子账号查询")
    @GetMapping("/{merchantNo}")
    public ResultEx<MerchantInfoVo> getMerchantInfo(@ApiParam(value = "商户号", required = true) @PathVariable String merchantNo) {
        return ResultEx.ok(merchantInfoFacade.getMerchantInfo(loginUserInfoHelper.getCustomerCode(true), merchantNo));
    }

    @DenyRepeatSubmit(type = RepeatSubmitTypeEnum.EXCLUSIVE_SUBMIT)
    @LogAnnotation
    @ApiOperation("子账号更新")
    @PostMapping("/{merchantNo}")
    public ResultEx<MerchantInfoVo> edit(@ApiParam(value = "商户号", required = true) @PathVariable String merchantNo, @RequestBody PMerchantInfoDto infoDto) {
        return merchantInfoFacade.edit(loginUserInfoHelper.getLoginInfo().getUserName(), loginUserInfoHelper.getUserId(true), loginUserInfoHelper.getCustomerCode(true), merchantNo, infoDto);
    }

}
